package com.pq.service.impl;

import com.pq.dao.product.ProductBannerDao;
import com.pq.dao.product.ProductDao;
import com.pq.pojo.order.OrderCart;
import com.pq.pojo.product.Product;
import com.pq.pojo.product.ProductBanner;
import com.pq.pojo.product.ProductImg;
import com.pq.service.product.ProductService;
import com.pq.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductBannerDao productBannerDao;
    @Autowired
    private ProductDao productDao;


    @Override
    public List<ProductBanner> findProductBanner() {
        List<ProductBanner> productList = productBannerDao.findProductBanner();
        return productList;
    }

    @Override
    public Product findProductById(Integer productId) {
        Product product = productDao.findProductById(productId);
        return product;
    }

    @Override
    public List<Product> findProductList(String byFlag, String orderCol, Integer startIndex, Integer rows) {
        List<Product> productList = productDao.findProductList(byFlag, orderCol, startIndex, rows);
        return productList;
    }

    @Override
    public List<Product> findProductTypeId(Integer logType,Integer typeId) {
        List<Product> productTypeList = productDao.findProductTypeId(logType,typeId);
        return productTypeList;
    }

    @Override
    public ProductImg findImagesByProductId(Integer productId, Integer imgType) {
        ProductImg productImg = productDao.findImagesByProductId(productId, imgType);
        return productImg;
    }

    @Override
    public SysResult findProductByList(Integer typeId, String orderFlag, Integer pageCurrent) {
        String orderCol="";
        if(orderFlag.equals("1")){
            orderCol = "sales";
        }else if(orderFlag.equals("2")) {
            orderCol = "price";
        }else {
            SysResult.fail();
        }
        int rows=5;
        int startIndex=(pageCurrent-1)*rows;
        List<Product> productList=productDao.findProductListByTypeId(typeId,startIndex,rows, orderCol);
        return SysResult.success(productList);
    }

    @Override
    public int doSaveOrderCart(Integer productId, Integer productCounts, Integer userId) {

        int row = productDao.doSaveOrderCart(productId, productCounts, userId);

        return row;
    }

    @Override
    public OrderCart doSaveOrderPayDirectly(Integer productId, Integer productCounts, Integer userId) {
        OrderCart orderCart = productDao.doSaveOrderCartDirectly(productId, productCounts, userId);
        return orderCart;
    }

    @Override
    public int insertOrderId(Integer orderId, String productId, Long orderCartId) {
        int row = productDao.insertOrderId(orderId, productId, orderCartId);
        return row;
    }


}
